using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Media;
using Tetris.Blocks;
using Tetris.Graphics;
using Tetris.Interfaces;

namespace Tetris.Levels
{
    public class DefaultLevel : ILevel
    {
        private readonly Background _background;
        private readonly Song _music;
        private BlockManager _blockManager;
        private GameGrid _grid;

        public long TimeLimit { get { return 2000; } }

        public DefaultLevel(Background background, Song music)
        {
            _background = background;
            _music = music;
            _grid = new GameGrid(10, 20, 445, 37, 260, 22);
            _blockManager = new BlockManager(_grid);
            MediaPlayer.Volume = 0.05f;
        }

        public void Initialize(IGameManager gameManager)
        {
            _background.Initialize(gameManager);
            _blockManager.Initialize(gameManager);
            MediaPlayer.Play(_music);
        }

        public void Update(IGameManager gameManager)
        {
            _background.Update(gameManager);
            _blockManager.Update(gameManager);
        }

        public void Draw(SpriteBatch spriteBatch, IGameManager gameManager, GameTime gameTime)
        {
            _background.Draw(spriteBatch, gameManager, gameTime);
            _blockManager.Draw(spriteBatch, gameManager, gameTime);
        }
    }
}